package com.xyz.service.impl;

import com.xyz.entity.ViolationRecord;
import com.xyz.entity.ViolationRecordProcessed;
import com.xyz.entity.request.ProcessRecordRequest;
import com.xyz.mapper.ViolationRecordProcessedMapper;
import com.xyz.service.IViolationRecordProcessedService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyz.service.IViolationRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 已处理的违章信息 服务实现类
 * </p>
 *
 * @author author
 * @since 2022-04-27
 */
@Service
public class ViolationRecordProcessedServiceImpl extends ServiceImpl<ViolationRecordProcessedMapper, ViolationRecordProcessed> implements IViolationRecordProcessedService {
    private final IViolationRecordService violationRecordService;

    public ViolationRecordProcessedServiceImpl(IViolationRecordService violationRecordService) {
        this.violationRecordService = violationRecordService;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void process(ProcessRecordRequest request) {
        ViolationRecordProcessed violationRecordProcessed = new ViolationRecordProcessed();
        BeanUtils.copyProperties(request, violationRecordProcessed);
        this.save(violationRecordProcessed);
        this.violationRecordService.lambdaUpdate().set(ViolationRecord::getIsProcessed, 1).eq(ViolationRecord::getId, request.getRecordId()).update();
    }
}
